package pers.sen.health.controller;

import org.apache.dubbo.config.annotation.Reference;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import pers.sen.health.entity.QueryPageBean;
import pers.sen.health.entity.Result;
import pers.sen.health.po.CheckItem;
import pers.sen.health.service.CheckItemService;

/**
 * @author Jason
 * @version 1.0.0
 * @date 2020/11/5 9:57
 * @Description TODO
 */
@RestController
public class CheckItemController {

    // 获取服务
    @Reference
    private CheckItemService checkItemService;

    // 查询所有检查项
    @GetMapping("checkitem/findAll")
    @PreAuthorize("hasRole('ROLE_ADMIN')")
//    @PreAuthorize("hasAuthority('FINDPAGE')")
    public Result findAll() {
        return new Result(checkItemService.list());
    }


    // 分页查询
    @PostMapping("checkitem/findPage")
    @PreAuthorize("hasRole('ROLE_ADMIN')")
    public Result findPage(@RequestBody QueryPageBean queryPageBean) {
        return new Result(checkItemService.findPage(queryPageBean));
    }

    // 新增修改

    /**
     * saveOrUpdate：通过传入的参数是否存在主键id来决定是添加还是修改的操作【修改有id（托管态），增无id（瞬时态）】
     *
     * @param checkItem 传递过来的参数
     * @return 响应结果
     */
    @PostMapping("checkitem/addOrUpdate")
    public Result addOrUpdate(@RequestBody CheckItem checkItem) {
        return new Result(checkItemService.saveOrUpdate(checkItem));
    }

    // 删除（改变显示状态）
    @PostMapping("checkitem/updateIsDeleteById")
    public Result updateIsDeleteById(@RequestBody CheckItem checkItem) {
        return new Result(checkItemService.updateIsDeleteById(checkItem));
    }
}
